<template>
    <div class="sub-layout user-content">
        <div class="sub-sidebar">
            <div class="search-bar">
                <div class="search-box">
                    <el-select v-model="search.value" placeholder="搜索用户..." filterable remote :remote-method="searchMethod" :loading="search.loading"
                        @change="searchChange">
                        <el-option v-for="item in search.list" :key="item.id" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                    <i class="icon i-search"></i>
                </div>
                <permission class="add" permission-key="user:addDept">
                    <a @click="showEditLayer(0)">
                        <i class="icon i-plus"></i>
                    </a>
                </permission>
            </div>
            <div class="side-nav">
                <el-tree node-key="id" :props="deptDefaultProps" :data="deptList" @node-click="nodeClick"></el-tree>
            </div>
        </div>
        <div class="sub-main">
            <div class="content" v-if="currentData.name">
                <div class="section-info">
                    <span class="name">{{currentData.name}}</span>
                    <template>
                        <permission permission-key="user:editDept">
                            <button @click="showEditLayer(1)">修改</button>
                        </permission>
                        <permission permission-key="user:deleteDept">
                            <button class="btn-delete" @click="showDeleteLayer(0)">删除</button>
                        </permission>
                        <permission permission-key="user:addDept">
                            <button @click="showEditLayer(2)">添加子类别</button>
                        </permission>
                    </template>
                </div>
                <div class="section section-table">
                    <div class="panel-title">
                        <span class="title">用户列表</span>
                        <div class="title-right">
                            <permission permission-key="user:addUser">
                                <router-link :to="{path: '/system/user/edit', query: {deptid: currentData.id}}">
                                    <button>添加用户</button>
                                </router-link>
                            </permission>
                        </div>
                    </div>
                    <div class="panel-content">
                        <el-table :data="tableData.data" border>
                            <el-table-column fixed label="用户姓名" width="80">
                                <template slot-scope="scope">
                                    <router-link :to="{path: '/system/user/detail', query: {userid: scope.row.id}}">{{scope.row.name}}</router-link>
                                </template>
                            </el-table-column>
                            <el-table-column prop="email" label="邮箱地址" width="170">
                            </el-table-column>
                            <el-table-column prop="companyName" label="所属公司" width="200">
                            </el-table-column>
                            <el-table-column prop="departmentName" label="所属部门" width="180">
                            </el-table-column>
                            <el-table-column prop="position" label="职位" width="138">
                            </el-table-column>
                            <el-table-column prop="roles" label="角色" width="125">
                            </el-table-column>
                            <el-table-column prop="identity" label="身份证号" width="170">
                            </el-table-column>
                            <el-table-column prop="phone" label="手机号" width="120">
                            </el-table-column>
                            <el-table-column prop="cdate" label="添加时间" width="120">
                            </el-table-column>
                            <el-table-column prop="remark" label="备注信息" width="250">
                            </el-table-column>
                            <el-table-column fixed="right" label="操作" width="120">
                                <template slot-scope="scope">
                                    <permission permission-key="user:updateUser">
                                        <router-link :to="{path: '/system/user/edit', query: {userid: scope.row.id}}">修改</router-link>
                                    </permission>
                                    <permission permission-key="user:deleteUser">
                                        <a class="delete" @click="showDeleteLayer(scope.row.id)">删除</a>
                                    </permission>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination v-if="tableData.total" :current-page="tableData.index" :page-sizes="[tableData.sizes,tableData.sizes*2, tableData.sizes*3, tableData.sizes*4]"
                            :page-size="tableData.size" :total="tableData.total" layout="total, sizes, prev, pager, next, jumper"
                            @size-change="tableSizeChange" @current-change="getTableData">
                        </el-pagination>
                    </div>
                </div>
            </div>
        </div>
        <!-- 编辑layer -->
        <layer :data="editLayerData" @on-cancel="closeEditLayer" @on-ok="editLayerConfirm">
            <div class="el-form">
                <div class="el-form-item is-required" :class="{'is-error':editLayerData.error}">
                    <label class="el-form-item__label" style="width: 100px;">类别名称</label>
                    <div class="el-form-item__content" style="margin-left: 112px;">
                        <div class="el-input">
                            <input autocomplete="off" type="text" validateevent="true" class="el-input__inner" placeholder="请输入类别名称" v-model="editLayerData.name"
                                @blur="layerInputBlur">
                        </div>
                        <div class="el-form-item__error" v-if="editLayerData.error">请输入类别名称</div>
                    </div>
                </div>
            </div>
        </layer>
        <!-- 删除layer  -->
        <layer :data="deleteLayerData" @on-ok="deleteLayerConfirm"></layer>
    </div>
</template>

<script>
    import './user.less'
    import userManage from '@/mixins/userManage'
    export default {
        name: 'user',
        mixins: [userManage],
        data() {
            return {
            }
        },
        computed: {
            id() {
                return this.$route.query.id || 0
            }
        },
        components: {
        },
        mounted() {
            this.$store.dispatch('setBreadData', [
                {
                    name: '系统管理'
                },
                {
                    name: '用户管理'
                }
            ]);
        },
        methods: {
        }
    }
</script>